package com.ruibang.glass.iso.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.ruibang.glass.iso.domain.req.FileCategoryReq;
import com.ruibang.glass.iso.entity.FileCategory;
import com.ruibang.glass.iso.service.impl.FileCategoryService;
import com.teaming.cloud.framework2.common.model.ResultBody;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * @Author: songJinKang
 * @CreateTime: 2024-06-05  15:34
 * @Description: TODO
 * @Version: 1.0
 */

@RestController
@RequestMapping("/api/iso/fileCategory")
@Api(value = "文件类别控制器", tags = {"文件类别控制器"})
public class FileCategoryController {

    @Autowired
    private FileCategoryService fileCategoryService;

    @PostMapping("/pageQuery")
    @ApiOperation(value = "分页查询文件类别信息", response = ResultBody.class)
    public ResultBody<IPage<FileCategory>> pageQuery(@RequestBody FileCategoryReq fileCategoryReq) {
        return ResultBody.success(fileCategoryService.pageQuery(fileCategoryReq));
    }

    @GetMapping("/list")
    @ApiOperation(value = "文件类别列表", response = ResultBody.class)
    public ResultBody<List<FileCategory>> list() {
        return ResultBody.success(fileCategoryService.list());
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存文件类别", response = ResultBody.class)
    public ResultBody save(@RequestBody @Valid FileCategory fileManage) {
        fileCategoryService.save(fileManage);
        return ResultBody.success();
    }

    @DeleteMapping("/deleteById/{id}")
    @ApiOperation(value = "根据id删除", response = ResultBody.class)
    public ResultBody pageQuery(@PathVariable String id) {
        fileCategoryService.removeById(id);
        return ResultBody.success();
    }

    @PutMapping("/edit")
    @ApiOperation(value = "查询记录", response = ResultBody.class)
    public ResultBody edit(@RequestBody @Valid FileCategory fileManage) {
        fileCategoryService.updateById(fileManage);
        return ResultBody.success();
    }
}
